﻿#ifndef CONFIRMDEVICE_H
#define CONFIRMDEVICE_H

#include <QDialog>
#include <QSerialPort>
#include <QTimer>
#include <QVector>
#include "Main/datatype.h"
class DockWidgetCTD;
class ConfirmDevice : public QObject
{
    Q_OBJECT
public:
    explicit ConfirmDevice(QObject *parent = nullptr);
    QSerialPort serial;
    QSerialPort serial_TD;
    QSerialPort serial_T;
    QSerialPort serial_CTD;
signals:
    void sendTypeData(Message_t);
    void sendTypeTSC(Message_t);
    void send_Set_Btn_Status(QByteArray);
    void send_Stop_After_Change_Status();
    void send_Flash_Info(QByteArray);
    void sendComRemove_TDSC_Signal(QString& portName);
    void sendComRemove_TSC_Signal(QString& portName);
    void sendStopTimer();
    //void sendStartTimer();
    void sendFlashDataFromTSC(QByteArray);
    void sendSampleRotateTSC(QByteArray);
private:
    QTimer m_timer;
    QTimer adapterDeviceTimer;
    QByteArray initReadAll;

    QVector<QString> m_serialList;
    QByteArray response_TD;
    QByteArray responseTSC;
    int g_com_cont=0;
    QVector<QByteArray> DataMsg;
    bool isCrashFlag=false;
    QByteArray start_Sample;
    QByteArray arrLED;
    QList<QSerialPortInfo> infos;

    QByteArray arrTemperatureCoefficientBTSC;

    DockWidgetCTD* dockWidgetTsc;
private slots:
    void readResponse_TD();
    void readResponse_T();
    bool SetSerialPortParam(QSerialPort *serial, int Baudrate,QByteArray serialCommand);
    void setTemperatureCoefficientABCD(QByteArray,QByteArray);
    void reciveTemperatureCD(QByteArray);

    void recivePressureCoefficientAB(QByteArray);
    void recive_Pressure_CoefficientCD(QByteArray);
    void recive_Calibration_Time(QByteArray);
    void send_Calibration_Coefficien();
    void recive_Start_Sample(QByteArray);
    void recive_Stop_Sample();

    void getRotationDeviceTime();
    void get_Sample_Status();
    
    void send_Read_Flash_Using_DownLoad();
    void send_Once_Sample();

    void recvMessageFromDeviceConfigTSC(ModetoConfig);
    
public slots:
    void sendData_back();
    void initSerialPort();
    void initSerialPortBack(QString& portName);
    void send_Read_Sample_Config();
    void sendComRemove(QString& portName);
    void readAdapterResponse();
    void confirmCommandTCD();
};

#define ConfirmDeviceRelease Singleton<ConfirmDevice>::Release()
#define ConfirmDeviceInstance Singleton<ConfirmDevice>::GetInstance()

#endif // CONFIRMDEVICE_H
